package com.cuotibao.zhuoxiao.basics.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import com.cuotibao.zhuoxiao.basics.BaseApplication;

/**
 * @author hdx on 2019/5/6.
 */
public class ToastUtils {
    private static Toast mToast;

    public synchronized static void showToast(Context context, String content, int gravity) {
        if (content == null) return;
        if (mToast == null) {
            mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
        }
        mToast.setGravity(gravity, 0, 0);
        mToast.setText(content);
        mToast.show();
    }

    public synchronized static void showToast(int content, int gravity) {
        Context context = BaseApplication.getIns();
        showToast(context, context.getString(content), gravity);
    }

    public synchronized static void showToast(int content) {
        Context context = BaseApplication.getIns();
        showToast(context, context.getString(content), Gravity.CENTER);
    }

    public synchronized static void showToast(String content) {
        showToast(BaseApplication.getIns(), content, Gravity.CENTER);
    }

    public synchronized static void showCenterToast(String content) {
        showToast(BaseApplication.getIns(), content, Gravity.CENTER);
    }

    public synchronized static void showCenterToast(int content) {
        Context context = BaseApplication.getIns();
        showToast(context, context.getString(content), Gravity.CENTER);
    }
}
